#!/bin/sh

usage () {
	cat <<EOF>&2
Usage: ${0##*/} SUBVOLUMES...

Snapshot all Btrfs SUBVOLUMES to a read-only '.snapshots/SUBVOLUME/DATE'.

EOF
}

if [ $# -eq 0 ]; then
	usage
	exit 1
fi

for i; do
	root=$(findmnt -n --output TARGET -T "$i")
	sudo btrfs subvolume snapshot -r "$i" $root/.snapshots/"$(basename "$i")"/$(date +%F_%R:%S)
done
